<template>
	<view>
		<view class="top">
			<u-search :input-style="inputStyle" shape="square" placeholder="请输入客户名称" v-model="query" :showAction="false"></u-search>
		</view>

		<view class="u-page">
			<u-list >
				<u-list-item v-for="(item, index) in indexList" :key="index">
					<u-cell :title="`${item.linkman} ${item.phone}`" isLink @click="back(item)" :label="`${item.name}`">

					</u-cell>
				</u-list-item>
			</u-list>
		</view>
		<view class="wrap">
			<u-loadmore @loadmore="more()" :status="status" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				query:"",
				status: 'loadmore',
				page: 0,
				total: 0,
				inputStyle: {
					fontSize: '12px', //修改搜索框里面的文字大小
					width: "500rpx"
				},
				indexList: [

				],
				
			}
		},
		methods: {
			loadmore(data) {
				for (let i = 0; i < data.length; i++) {
					this.indexList.push(data[i])
				}
			},
			more() {
				console.log("点击了加载更多")
				if ((this.page + 1) * 15 >= this.total) {
					this.status = 'nomore'
					return;
				} else {
			
					this.status = 'loading';
					this.page = ++this.page;
			
					var that = this
					this.api.post("/customer/myCustomer", {
						companyId: that.$store.state.myCompanyId,
						query: that.query,
						count: 15,
						index: that.page
					}).then(res => {
						console.log(res.data)
						that.total = res.pageCount
						that.loadmore(res.data)
						console.log(res);
						if ((this.page + 1) * 15 >= this.total) this.status = 'nomore';
						else this.status = 'loadmore';
					})
				}
			},
			loadmore(data) {
				for (let i = 0; i < data.length; i++) {
					this.indexList.push(data[i])
				}
			},
			back(item) {
				// uni.navigateTo({
				// 	url:"/pages/neworder/neworder?id="+item.id+"&linkman="+item.linkman
				// })
				this.$store.state.custmoerName = item.linkman
				this.$store.state.custmoerId = item.id
				uni.navigateBack();
			},	
		},
		onLoad() {
			var that = this
			this.api.post("/customer/myCustomer", {
				companyId: that.$store.state.myCompanyId,
				query: that.query,
				count: 15,
				index: that.page
			}).then(res => {
				console.log(res.data)
				that.total=res.pageCount
				that.indexList = res.data
				console.log(res);
			})
		},
		watch: {
			query(newValue, oldValue) {
				this.status = 'loadmore',
				this.indexList = []
				this.page = 0
				var that = this
				this.api.post("/customer/myCustomer", {
					companyId: that.$store.state.myCompanyId,
					query: newValue,
					count: 15,
					index: that.page
				}).then(res => {
					console.log(res.data)
					that.total = res.pageCount
					that.loadmore(res.data)
					console.log(res);
				})
			},
		},

	}
</script>

<style>
	.wrap {
		padding: 24rpx;
	}
	
	.item {
		padding: 24rpx 0;
		color: $u-content-color;
		font-size: 28rpx;
	}
	.top {
		height: 100px;
		background-color: #BBBCC6;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}
</style>
